package com.yanqu.road.logic.activity.foxcard.game.effect;

import com.yanqu.road.entity.activity.foxcard.FoxBaseCard;
import com.yanqu.road.entity.activity.foxcard.FoxHandCard;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardTriggerType;

import java.util.Collections;
import java.util.List;

/**
 * 拥有时就能产生效果，但是产生的效果会逐渐递减
 * 持续回合|回合筹码|回合倍率|回合手牌上限
 */
public class FoxCardEffect14 extends FoxCardEffectBase {
    @Override
    protected void effectHandle(FoxCardGameLogic gameLogic, FoxHandCard handCard) {
        if (triggerType == eFoxCardTriggerType.ADD && handCard == null) {
            long roundRemain = Long.valueOf(effectConfig.getParamsList().get(0));
            effectCard.setEffectValues(Collections.singletonList(roundRemain));

            //回合手牌上限
            gameLogic.reCalcCardOpTimes();
        } else if (triggerType == eFoxCardTriggerType.AFTER_SCORE) {
            if (effectCard.getEffectValues().isEmpty()) {
                return;
            }
            long roundRemain = effectCard.getEffectValues().get(0);
            long addBaseScore = roundRemain * Long.valueOf(effectConfig.getParamsList().get(1));
            long addBaseMulti = roundRemain * Long.valueOf(effectConfig.getParamsList().get(2));
            List<FoxBaseCard> foxEffectCards = Collections.singletonList(effectCard);
            gameLogic.addBaseScore(addBaseScore, foxEffectCards, null); //加基础筹码
            gameLogic.addBaseMulti((int) addBaseMulti, foxEffectCards, null); //加基础倍率
        } else if (triggerType == eFoxCardTriggerType.ROUND_END) {
            if (effectCard.getEffectValues().size() > 0) {
                long roundRemain = effectCard.getEffectValues().get(0);
                roundRemain--;
                if (roundRemain <= 0) {
                    effectCard.setEffectValues(Collections.emptyList());
                } else {
                    effectCard.setEffectValues(Collections.singletonList(roundRemain));
                }
                //回合手牌上限减少
                gameLogic.reCalcCardOpTimes();
            }
            if (effectCard.getEffectValues().isEmpty()) {//效果用完销毁卡片
                gameLogic.destroyEffectCards(Collections.singletonList(effectCard));
            }
        }
    }
}
